/**
 * Created by sun on 2016/8/4.
 */
define(function (require) {
    var app = require('/../js/app');
    require('ui-table');
    app.useModule("ui.table");
    var datepicker = require('datepicker');
    var toastr =require('toastr');
    app.controller('countCtrl', ['$scope','$http',function ($scope, $http) {

        $scope.ctrlScope=$scope;

        $scope.orderParams = {
            url: "/admin/lottery/gitList"
        };
        datepicker($scope);
        //全局查询
        $scope.search = function() {
            //表格查询参数设置
            $scope.orderParams.ajaxParam=$scope.ctrlScope.itemsearch;
            //表格刷新
            $scope.orderParams.reload();
        };

        //全局查询重置
        $scope.reset=function(){
            $scope.ctrlScope.itemsearch={};
            $scope.orderParams.ajaxParam={};
            $scope.orderParams.reload();
        };

        $scope.addModalShow=function(){
            $scope.addModal=!$scope.addModal;
        }





        $scope.submitLottery=function(){
            var num="";

            if($scope.ctrlScope.lottery.addLottery==1){
                num= $scope.ctrlScope.lottery.getOneNum;
            }else{
                num= $scope.ctrlScope.lottery.getListNum;
            }
            if(num<1 || num == null){
                alert("数量必须大于0");
                return;
            }
            var param={
                type:$scope.ctrlScope.lottery.addLottery,
                mobile:$scope.ctrlScope.lottery.mobile,
                num:num
            }

            $http({
                method: 'POST',
                url: "/admin/lottery/addRaffleTicket",
                data:param,
            }).success(function(data) {
                console.info(data);
                if(data.result=="success"){
                    toastr.success("提交成功");
                    $scope.addModal=!$scope.addModal;
                    $scope.orderParams.reload();
                }else{
                    if(data.messageCode=="sys.error"){
                        toastr.error("系统异常");
                    }else{
                        toastr.error(data.messageText);
                    }
                }

            }).error(function(data) {
            });
        }
    }]);
});